package models;

import play.*;
import play.db.jpa.*;

import javax.persistence.*;
import java.util.*;
@Entity
public  class PlaceInfo extends Model  {
    

	private String formatted_placeName;
	private int placeType;
	private long cordinateId;
	private Cordinate cordinate;
	public PlaceInfo(double latitude, double longitude, String name){
		this.formatted_placeName = name;
		this.cordinateId = -1;
		
	}
	
    public PlaceInfo (String name){
    	this.formatted_placeName = name;
    }
    public  static PlaceInfo findOrCreatePlaceInfo(double latitude , double longitude,String name){
    	Cordinate cordinate = Cordinate.findOrCreate(latitude, longitude);
    	PlaceInfo placeInfo = null;
    	if(cordinate.getId() == null){
    		placeInfo = new PlaceInfo(latitude, longitude, name);
    		return placeInfo;
    	}
    	placeInfo = PlaceInfo.find("cordinateId = ?", cordinate.getId()).first();
    	return placeInfo;
    }
	public Cordinate getCordinate() {
		if(this.cordinate == null){
			this.cordinate = Cordinate.findById(this.getCordinateId());
        }
		return this.cordinate;
	}
	public void setCordinate(Cordinate cordinate) {
		this.cordinateId = cordinate.getId();
	}
	public String getFormatted_placeName() {
		return formatted_placeName;
	}
	public void setFormatted_placeName(String formatted_placeName) {
		this.formatted_placeName = formatted_placeName;
	}
	public int getPlaceType() {
		return placeType;
	}
	public void setPlaceType(int placeType) {
		this.placeType = placeType;
	}
	public long getCordinateId() {
		return cordinateId;
	}
	public void setCordinateId(long cordinateId) {
		this.cordinateId = cordinateId;
	}
}
